#include "swegl/common.h"
#include "swegl/math.h"

namespace swegl
{

Matrix3x3 Quaternion::toMatrix3x3() const
{
	sweglWarning("check Quaternion::toMatrix3x3()");
	float x2 = x + x;
	float y2 = y + y;
	float z2 = z + z;

	float xx = x * x2;
	float xy = x * y2;
	float xz = x * z2;

	float yy = y * y2;
	float yz = y * z2;
	float zz = z * z2;

	float wx = w * x2;
	float wy = w * y2;
	float wz = w * z2;

	Matrix3x3 m;
	m[0][0] = 1.0f - (yy + zz);
	m[1][0] = xy - wz;
	m[2][0] = xz + wy,
	m[0][1] = xy + wz;
	m[1][1] = 1.0f - (xx + zz);
	m[2][1] = yz - wx;
	m[0][2] = xz - wy;
	m[1][2] = yz + wx;
	m[2][2] = 1.0f - (xx + yy);
	return m;

	/*
	mat[ 0 ][ 0 ] = 1.0f - ( yy + zz );
	mat[ 0 ][ 1 ] = xy - wz;
	mat[ 0 ][ 2 ] = xz + wy;

	mat[ 1 ][ 0 ] = xy + wz;
	mat[ 1 ][ 1 ] = 1.0f - ( xx + zz );
	mat[ 1 ][ 2 ] = yz - wx;

	mat[ 2 ][ 0 ] = xz - wy;
	mat[ 2 ][ 1 ] = yz + wx;
	mat[ 2 ][ 2 ] = 1.0f - ( xx + yy );
	*/
}

}

